package Servidor;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author kiko
 */
public class GerenciadorArquivo {

    public static boolean nomeEncontrado(String path, String expression) {
        BufferedReader in;
        String str;
        try {
            in = new BufferedReader(new FileReader(path));
            while (in.ready()) {
                str = in.readLine();
                if (str.equals(expression)) {
                    return true;
                }
            }
            in.close();
            return false;
        } catch (IOException ex) {
            Logger.getLogger(GerenciadorArquivo.class.getName()).log(Level.SEVERE, null, ex);
            return false;
        }
    }
    
    public static ArrayList<String> getListFilesUser(String email) {
        BufferedReader in;
        String str;
        ArrayList<String> list = new ArrayList();
        try {
            in = new BufferedReader(new FileReader("FTP" + File.separator + "users" + File.separator + email));
            while (in.ready()) {
                str = in.readLine();
                list.add(str);
            }
            in.close();
            return list;
        } catch (IOException ex) {
            Logger.getLogger(GerenciadorArquivo.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
    
    public static boolean arquivoExiste(String path) {
        File file = new File(path);
        if (file.exists()) {
            return true;
        } else {
            return false;
        }
    }
}
